package com.example.yls.demoa;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    private Button btnSearch;
    private EditText edtNo;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnSearch =findViewById(R.id.btn_search);
        edtNo = findViewById(R.id.edt_no);
        btnSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String No = edtNo.getText().toString();
                MyDataBaseHelper helper = new MyDataBaseHelper(MainActivity.this);
                SQLiteDatabase db = helper.getReadableDatabase();
                String where ="no ="+No;
                Cursor cursor= db.query("student",null,where,null,null,null,null);
                cursor.moveToFirst();
                String name = cursor.getString(2);
                String birth = cursor.getString(3);
                String phone = cursor.getString(4);

                Intent intent = new Intent();
                intent.setClass(MainActivity.this,StudentActivity.class);
                intent.putExtra("NO",No);
                intent.putExtra("NAME",name);
                intent.putExtra("BIRTH",birth);
                intent.putExtra("PHONE",phone);
                startActivity(intent);



            }
        });
    }
}
